package chapter14;

/**
 * @author : DuJiabao
 * @Date : 2021/2/24 20:59
 * @Project : thinking-in-java
 * @File : null.java
 * @Desc :
 */
class Gum {
  static {
    System.out.println("Loading Gum");
  }
}

class Candy {
  static {
    System.out.println("Loading Candy");
  }
}

class Cookie {
  static {
    System.out.println("Loading Cookie");
  }
}

public class SweetShop {
  public static void main(String[] args) {
    System.out.println("Inside main");
    new Candy();
    System.out.println("After creating Candy");
    try {
      Class.forName("chapter14.Gum");  // 通过名称获取类的引用，切记，一定要写出具体的包名再到class名
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    System.out.println("After Class.forName(\"Gum\")");
    new Cookie();
    System.out.println("After creating Cookie");
  }
}




